home *** CD-ROM | disk | FTP | other *** search
/ QuickTime for the Web (2nd Edition) / QuickTime for the Web (2nd Edition).iso / pc / Demos / Mac / Matthew's Behaviors / KeyboardEventƒ / KeyboardEvent < prev    next >
Encoding:
INI File  |  2001-09-10  |  2.5 KB  |  67 lines

  1. [Name]
  2. KeyBoardEvent v1.0 - provides framework for keypress events
  3. By Matthew Peterson, matthew@pinoko.berkeley.edu
  4.  
  5. [Description]
  6. 2-29-2000
  7. Currently Quicktime doesn't have much of an interface for text
  8. or keyboard interaction. All one can do is test if a specific key
  9. is currently being pressed. Thus in order to check which key is
  10. pressed, it is necessary to check each and every key in a loop.
  11. This sounds bad, but it turns out that for most machines, we
  12. can get away with it. I've done a couple of things to help speed
  13. this process up. For example, I've made separate behaviors for
  14. different sets of characters. Just add the ones you want to
  15. check (letters, numbers, control...) as an addition to this 
  16. behavior.
  17.  
  18. To use, place this behavior in a sprite, and pick a set of
  19. characters to poll by placing one or more of the accompanying 
  20. accessory behaviors on the same sprite. In the parameters,
  21. set the ID of the event you would like to have executed once
  22. a key is pressed.
  23.  
  24. You can now place QScript code in your specified custom event
  25. to handle keyboard events. The following Global Variables should
  26. be used to help in this process:
  27.  
  28. Global Variables:
  29. 1) KeyBoardOn -- Set to true to poll the keyboard.
  30. 2) WhichKeyN -- The ascii number of the key pressed. You may
  31.                     use the accompanying asciiArray behavior to give
  32.                      your scripts access to the ascii table. But in general
  33.                     it is sufficient to know that 48='0'and 65='A'.
  34. 3) oldKeyN -- The previous value of WhichKeyN. It is often useful to 
  35.                       check if oldKeyN = WhichKeyN.
  36. 4) IsCap -- When using the LetterKeys, IsCap will tell you if the letter
  37.                  pressed is a capital letter or not.
  38.  
  39. Revision History:
  40. 2-19-2000 : wrote it
  41. 2-29-2000: made it faster by placing all the key polling in the same event.
  42.  
  43. [Parameters]
  44.  
  45. On KeyPress Event ID:, MP_KBCustomEventID,79
  46.  
  47. [Idle]
  48. GlobalVars KeyBoardOn 
  49. IF(KeyBoardOn)
  50.     ExecuteEvent(200079)
  51. ENDIF
  52.  
  53. [200079 MP_KeyboardEvent]
  54. GlobalVars whichkeyN oldkeyN IsCap
  55. //This is a simple polling structure. It executes events
  56. //That check if keys are being pressed, then if there is a
  57. //change in the current keypressed status, it executes the
  58. //custom event defined by the user.
  59. whichkeyN = -1 //cleared state
  60. ExecuteEvent(200072) //Poll the keys.
  61.  
  62. IF(whichkeyN ≠ oldkeyN AND whichkeyN > 0)//If new key
  63.   isCap = KeyIsDown(kShiftKey,"") OR KeyIsDown(kCapsLockKey,"")  AND NOT KeyIsDown(kShiftKey | kCapsLockKey,"")
  64.     ExecuteEvent($MP_KBCustomEventID)
  65. ENDIF
  66.  
  67. oldkeyN = whichKeyN  //remember this key for next idle event.